package ${ViewRootPackage};
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.askj.integration.encrypt.annotation.AesResponseEncrypt;
import com.askj.integration.encrypt.support.AesEncryptApiResponseFallback;
import com.askj.integration.infrastructure.support.PageResult;
import com.askj.integration.interfaces.AbstractControl;
import com.askj.integration.security.response.ResponseResultBody;
import com.askj.modules.config.BaseUserInfo;
import org.springframework.web.bind.annotation.*;
import com.askj.integration.security.response.ResponseType;
import com.askj.integration.security.response.SystemResponse;
import ${ViewRootPackage}.${entity}View;
import ${ViewRootPackage}.${entity}DetailView;
import ${VIEWS_QueryConditionPackage}.${entity}Condition;
import ${VIEWS_AppPackage}.${entity}Representation;
import com.askj.annotation.AppLog;
import com.askj.integration.limiting.annotation.RateLimiter;
import java.util.List;


/**
 * ${table.comment!} API
 * @author ${author}
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping
@Api(tags = "APP-${table.comment!}-VIEW接口")
public class ${entity}RepresentationApi extends AbstractControl {

    private final ${entity}Representation representation;

	/**
	 * 详情
	 */
	@AppLog("获取${table.comment!}详情")
	@ApiOperation(value = "获取指定${table.comment!}详情", notes = "获取指定${table.comment!}详情",response =${entity}DetailView.class)
	@ApiParam(name = "id", required = true, type = "String",  example = "12")
	@ResponseResultBody
	@GetMapping(value = {"/v1/{id}/detail"})
	@AesResponseEncrypt(fallbackFactory = AesEncryptApiResponseFallback.class)
	@RateLimiter(name = "${table.name}",   interval= 1000, fallbackFactory = ${Entity}RateLimiterFallback.class)
	public ${entity}DetailView ${entity}Detail(@PathVariable String id) {
		return representation.detail(id);
	}

    /**
     * 分页查询
     * @return
     */
    @AppLog("分页查询${table.comment!}")
    @ApiOperation(value = "分页查询${table.comment!}")
    @AesResponseEncrypt(fallbackFactory = AesEncryptApiResponseFallback.class)
    @ResponseResultBody
    @RateLimiter(name = "${table.name}",   interval= 1000, fallbackFactory = ${Entity}RateLimiterFallback.class)
    @GetMapping(value = {"/v1/query"})
    public PageResult<${entity}View> pageable${entity}Records(${entity}Condition condition) {
        if (Objects.isNull(condition)) {
    			condition = new ${entity}Condition();
    	}
        return representation.pageable(condition);
    }

    @Override
    public String loginId() {
        return BaseUserInfo.getLoginId();
    }


    public static class ${entity}RateLimiterFallback implements RateLimiterFallback {

        @Override
        public Object fallback(IRateLimiter limiter) {
              throw new ApplicationException("服务繁忙，请稍后再试");
        }
    }
}
